import lzma

data = []
with lzma.open("aligned.fasta.xz",'rb') as f:
    while True:
        name = f.readline()
        if not name:
            break
        seq = f.readline()
        data.append((name.decode("utf-8").strip()[1:],seq.decode("utf-8").strip()))
    a = [ l.decode("utf-8") for l in f]
    print(a)

with open("aligned.fasta","w",encoding="utf8") as f:
    f.writelines(a)

## 长度
for g in data:
    print(f"{g[0]} is {len(g[1])} long")

## 去除 -
for g in data:
    print(f'''{g[0]} is {len(''.join(g[1].split("-")))} log without -''')

## 按名排序
data_name = sorted(data,key=lambda x: x[0])
for g in data_name:
    print(g[0])

## 按长逆序
data_len = sorted(data,key=lambda g:len(''.join(g[1].split("-"))))
for g in data_len:
    print(f'''{g[0]} is {len(''.join(g[1].split("-")))} log without -''')


